
const Hotel = require('./Hotel')
const SearchEngine = require('./SearchEngine')
const Rate = require('./Rate')
const Budget = require('./Budget')
const Stay = require('./Stay')

class AppHotel {
  constructor () {
    this.hotels = []
    this.searchEngine = new SearchEngine()
    this.budgets = new Budget()
  }

  registerHotels (hotels) {
    const self = this
    hotels.map(hotel => {
      self.registerHotel(hotel)
    })
  }

  registerHotel (hotel) {
    this.hotels.push(new Hotel(hotel.name, hotel.rating, new Rate(hotel.rate)))
  }

  searchHotelLowerPrice (budget) {
    return this.searchEngine.findCheaperHotel(budget)
  }

  createBudgets (hotels, stringStay) {
    const stay = new Stay(stringStay)
    return this.budgets.createBudgets(hotels, stay)
  }

  setBudgets (budgets) {
    this.budgets = budgets
  }

  getBudgets () {
    return this.budgets
  }

  getHotels () {
    return this.hotels
  }
}

module.exports = AppHotel
